package com.bobi.result;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.ToString;
import org.springframework.http.HttpStatus;


@Data
@Schema(name = "Result", description = "返回对象工具包")
@ToString
public class Result<T> implements ResponseState {
    @Schema(name = "state", description = "状态码")
    private Integer state;// 状态码
    @Schema(name = "msg", description = "消息提示")
    private String msg; //消息提示
    //返回数据
    @Schema(name = "data", description = "返回的数据对象")
    private T data;

    private Result(Integer state, String msg, T data) {
        this.data = data;
        this.msg = msg;
        this.state = state;
    }

    public static <T> Result<T> ok(T data) {
        return new Result<T>(HttpStatus.OK.value(), "OK", data);
    }

    public static <T> Result<T> error() {
        return new Result<T>(SERVER_ERROR, "服务器异常", null);
    }

    public static <T> Result<T> error(Integer state, String msg) {
        return new Result<T>(state, msg, null);
    }

}
